package com.zyf.chapter02.behavior.iterator.snapshot;

import java.util.Vector;

/**
 * @author yifeng
 */
public class ArrayList<E> implements List<E> {

    Vector<E> vector = new Vector();

    @Override
    public Iterator<E> iterator() {
        return new SnapshotArrayIterator<>(this);
    }

    @Override
    public int size() {
        return vector.size();
    }

    @Override
    public E get(int index) {
        return vector.get(index);
    }

    @Override
    public boolean add(E e) {
        return vector.add(e);
    }

    @Override
    public void remove(E e) {
        vector.remove(e);
    }

    public static void main(String[] args) {
        ArrayList<String> names = new ArrayList<>();
        names.add("y");
        names.add("yf");
        names.add("zyf");

        Iterator<String> iterator = names.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.currentItem());
            iterator.next();
        }
    }


}
